package Zoo.Handler;




import Zoo.Entity.ZooparkEntity;
import Zoo.Impl.ZoomenServiceImpl;
import Zoo.Service.ZoomenService;
import Zoo.View.ZoomanView.UpdateZooparkView1;
import Zoo.View.ZoomanView.ZoomenView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 动物饲养员的园区信息界面
 */
public class UpdateZooparkView1Handler implements ActionListener {
    private UpdateZooparkView1 updateZooparkView1;
    private ZoomenView zoomenView;

//    public AddAnimalViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1){
//        this.addZoomenView=addZoomenView;
//        this.leaderView1=leaderView1;
//    }

    public UpdateZooparkView1Handler(UpdateZooparkView1 updateZooparkView1, ZoomenView zoomenView) {
        this.updateZooparkView1=updateZooparkView1;
        this.zoomenView=zoomenView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("修改".equals(text)){
            ZoomenService zoomenService=new ZoomenServiceImpl();
            ZooparkEntity zooparkEntity =updateZooparkView1.buildUpdatedZooparkEntity();
            boolean updateResult=zoomenService.update(zooparkEntity);
            if(updateResult){
                //重新加载表格查到最新数据
                zoomenView.reloadTable();
                updateZooparkView1.dispose();
            }else{
                JOptionPane.showMessageDialog(updateZooparkView1,"修改失败");

            }

        }
    }

}
